package com.letoy.study.service.Impl;

import com.letoy.study.dao.TokenMapper;
import com.letoy.study.entity.TokenInfo;
import com.letoy.study.service.TokenService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.letoy.study.utils.Constants.SUCCESS;
import static com.letoy.study.utils.Constants.SYSTEM_ERROR;

@Service
public class TokenServiceImpl implements TokenService {

    @Resource
    TokenMapper tokenMapper;

    @Override
    public int updateTokenInfo(TokenInfo tokenInfo) {
        if (tokenMapper.updateTokenInfo(tokenInfo) >= 1) {
            return SUCCESS;
        } else {
            return SYSTEM_ERROR;
        }

    }

    @Override
    public int cleanSystemToken(String systemToken) {
        if (tokenMapper.cleanSystemToken(systemToken) >= 1) {
            return SUCCESS;
        } else {
            return SYSTEM_ERROR;
        }
    }

    @Override
    public TokenInfo getTokenInfoByUserId(String userId) {
        return tokenMapper.getTokenInfoByUserId(userId);
    }

    @Override
    public int addNewUser(TokenInfo tokenInfo) {
        return tokenMapper.addNewUser(tokenInfo);
    }
}
